package com.yuelife.service.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.yuelife.service.pojo.SOrderItem;
import com.yuelife.service.pojo.SProduct;
import com.yuelife.service.service.SOrderItemService;
import entity.Result;
import entity.StatusCode;
import io.swagger.annotations.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/
@Api(value = "SOrderItemController")
@RestController
@RequestMapping("/sOrderItem")
@CrossOrigin
public class SOrderItemController {

    @Autowired
    private SOrderItemService sOrderItemService;

    /***
     * SOrderItem分页条件搜索实现
     * @param sOrderItem
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "SOrderItem条件分页查询",notes = "分页条件查询SOrderItem方法详情",tags = {"SOrderItemController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "SOrderItem对象",value = "传入JSON数据",required = false) SOrderItem sOrderItem, @PathVariable  int page, @PathVariable  int size){
        //调用SOrderItemService实现分页条件查询SOrderItem
        PageInfo<SOrderItem> pageInfo = sOrderItemService.findPage(sOrderItem, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * SOrderItem分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "SOrderItem分页查询",notes = "分页查询SOrderItem方法详情",tags = {"SOrderItemController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用SOrderItemService实现分页查询SOrderItem
        PageInfo<SOrderItem> pageInfo = sOrderItemService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param sOrderItem
     * @return
     */
    @ApiOperation(value = "SOrderItem条件查询",notes = "条件查询SOrderItem方法详情",tags = {"SOrderItemController"})
    @PostMapping(value = "/search" )
    public Result<List<SOrderItem>> findList(@RequestBody(required = false) @ApiParam(name = "SOrderItem对象",value = "传入JSON数据",required = false) SOrderItem sOrderItem){
        //调用SOrderItemService实现条件查询SOrderItem
        List<SOrderItem> list = sOrderItemService.findList(sOrderItem);
        return new Result<List<SOrderItem>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "SOrderItem根据ID删除",notes = "根据ID删除SOrderItem方法详情",tags = {"SOrderItemController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用SOrderItemService实现根据主键删除
        sOrderItemService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改SOrderItem数据
     * @param sOrderItem
     * @param id
     * @return
     */
    @ApiOperation(value = "SOrderItem根据ID修改",notes = "根据ID修改SOrderItem方法详情",tags = {"SOrderItemController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @PutMapping(value="/{id}")
    public Result update(@RequestBody @ApiParam(name = "SOrderItem对象",value = "传入JSON数据",required = false) SOrderItem sOrderItem, @PathVariable Integer id){
        //设置主键值
        sOrderItem.setItemId(id);
        //调用SOrderItemService实现修改SOrderItem
        sOrderItemService.update(sOrderItem);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增SOrderItem数据
     * @param sOrderItem
     * @return
     */
    @ApiOperation(value = "SOrderItem添加",notes = "添加SOrderItem方法详情",tags = {"SOrderItemController"})
    @PostMapping
    public Result add(@RequestBody  @ApiParam(name = "SOrderItem对象",value = "传入JSON数据",required = true) SOrderItem sOrderItem){
        //调用SOrderItemService实现添加SOrderItem
        sOrderItemService.add(sOrderItem);
        return new Result(true,StatusCode.OK,"添加成功");
    }



    /***
     * 根据ID查询SOrderItem数据
     * @param id
     * @return
     */
    @ApiOperation(value = "SOrderItem根据ID查询",notes = "根据ID查询SOrderItem方法详情",tags = {"SOrderItemController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @GetMapping("/{id}")
    public Result<SOrderItem> findById(@PathVariable Integer id){
        //调用SOrderItemService实现根据主键查询SOrderItem
        SOrderItem sOrderItem = sOrderItemService.findById(id);
        return new Result<SOrderItem>(true,StatusCode.OK,"查询成功",sOrderItem);
    }

    /***
     * 查询SOrderItem全部数据
     * @return
     */
    @ApiOperation(value = "查询所有SOrderItem",notes = "查询所SOrderItem有方法详情",tags = {"SOrderItemController"})
    @GetMapping
    public Result<List<SOrderItem>> findAll(){
        //调用SOrderItemService实现查询所有SOrderItem
        List<SOrderItem> list = sOrderItemService.findAll();
        return new Result<List<SOrderItem>>(true, StatusCode.OK,"查询成功",list) ;
    }

    /**
     * 订单id查订单明细
     * @param orderId
     * @return
     */
    @GetMapping(value = "/find/{orderId}")
    public Result<List<SOrderItem>> fnidSOrderItemBySOrderId(@PathVariable("orderId") Integer orderId){
        List<SOrderItem> sOrderItems = sOrderItemService.fnidSOrderItemBySOrderId(orderId);
        return new Result<List<SOrderItem>>(true, StatusCode.OK,"查询成功",sOrderItems) ;

    }

}
